<template>
	<!-- 头部购物车组件 -->
	<div class="headerCart">
		<a href="javascript:;" @click.prevent="handleCart">
			<span>购物车{{cartItemsCount}}</span>
		</a>
	</div>
</template>

<script>
	import {mapGetters} from 'vuex'
	export default{
		name:'HeaderCart',
		components:{},
		computed:{
			// cart模块带有命名空间 namedspace
			...mapGetters('cart',{
				// Vuex store中定义的getter 得到购物车商品数量itemsCount
				// 将this.cartItemsCount 映射为 this.$store.getters['cart/itemsCount']
				cartItemsCount:'itemsCount'
			})
		},
		methods:{
			handleCart(){
				this.$router.push('/cart')
			}
		}
	}
</script>

<style scoped>
.headerCart {
    display: inline-block; 
    position: relative;
    text-align: center;
    width: 100px;
    height: 30px;
    margin-top: 20px;
    margin-bottom: 20px;
    cursor: pointer;
    margin-left: 20px;
    background-color:red;
    vertical-align: middle;
}

.headerCart a {
    text-decoration: none;
    color: white;
    
}
.headerCart a > span{
  position: absolute;
  left: 2px;
  right: 2px;
  bottom: 5px;
}
</style>